package owl2vowl.parser.vowl;

import owl2vowl.constants.VowlAttribute;
import owl2vowl.model.data.VowlData;
import owl2vowl.parser.helper.ComparisonHelper;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLNamedObjectVisitor;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class ImportedChecker implements OWLNamedObjectVisitor {
	private final VowlData vowlData;
	private final OWLOntologyManager manager;
	private OWLOntology loadedOntology;
	private String loadPath;

	public ImportedChecker(VowlData vowlData, OWLOntologyManager manager, OWLOntology loadedOntology, String loadPath) {
		this.vowlData = vowlData;
		this.manager = manager;
		this.loadedOntology = loadedOntology;
		this.loadPath = loadPath;
	}

	public void execute() {
		this.vowlData.getEntityMap().values().forEach((abstractEntity) -> {
			IRI entityIri = abstractEntity.getIri();
			if (!entityIri.toString().contains("http://owl2vowl.de#")) {
				if (ComparisonHelper.hasDifferentNameSpace(entityIri.toString(), this.loadedOntology, this.loadPath)) {
					this.addImportedAttribute(entityIri);
				}

			}
		});
	}

	protected void addImportedAttribute(IRI iri) {
		this.vowlData.getEntityForIri(iri).addAttribute(VowlAttribute.IMPORTED);
	}

	public void visit(@Nonnull OWLClass owlClass) {
		if (!owlClass.isOWLThing() && !owlClass.isOWLNothing()) {
			this.addImportedAttribute(owlClass.getIRI());
		}
	}

	public void visit(@Nonnull OWLObjectProperty owlObjectProperty) {
		this.addImportedAttribute(owlObjectProperty.getIRI());
	}

	public void visit(@Nonnull OWLDataProperty owlDataProperty) {
		this.addImportedAttribute(owlDataProperty.getIRI());
	}

	public void visit(@Nonnull OWLNamedIndividual owlNamedIndividual) {
	}

	public void visit(@Nonnull OWLOntology owlOntology) {
	}

	public void visit(@Nonnull OWLDatatype owlDatatype) {
		this.addImportedAttribute(owlDatatype.getIRI());
	}

	public void visit(@Nonnull OWLAnnotationProperty owlAnnotationProperty) {
	}
}